package com.example.happiness.mapper;

import com.example.happiness.pojo.Serve;
import com.example.happiness.pojo.adminvo.AdminServeVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
@Mapper
public interface ServeMapper {
    int deleteByPrimaryKey(Integer sid);

    int insert(Serve record);

    int insertSelective(Serve record);

    Serve selectByPrimaryKey(Integer sid);

    int updateByPrimaryKeySelective(Serve record);

    int updateByPrimaryKey(Serve record);

    @Select("select sid, sname, cid, price, time, state, content,image,createtime from serve where cid=#{cid}")
    Serve getserve(Integer cid);

    @Select("select s.sid, s.sname,c.cname, s.price, s.time, s.state, s.content,c.cid,s.image,s.createtime from serve s,category c where s.cid=c.cid")
    List<AdminServeVO> selectServe();

    @Select("select sid, sname, cid, price, time, state, content,image,createtime from serve where state=#{state} and cid=#{cid}")
    List<Serve> getServeListandStateOne(Integer cid, Integer state);

    @Select("select sid from serve where sname=#{sname}")
    Integer getBysname(String sname);

    @Select("SELECT s.sid, COUNT(*) as count, s.price, s.sname, s.image\n" +
            "FROM `order` o\n" +
            "JOIN serve s ON o.sid = s.sid\n" +
            "GROUP BY s.sid, s.price, s.sname, s.image\n" +
            "ORDER BY count DESC\n" +
            "LIMIT 3;")
    List<Serve> getHotServe();
}
